package org.kotboot.service;/**
 * Created by jisong.sun on 2017/9/19.
 */

import org.kotboot.dao.DictDao;
import org.kotboot.domain.Dict;
import org.kotboot.enums.BoolState;
import org.kotboot.kit.KMap;
import org.kotboot.module.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.kotboot.module.Res;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * jisong.sun 2017/9/19 9:38
 */
@Service
public class DictServ {

    private static Logger log = LoggerFactory.getLogger(DictServ.class);

    @Resource
    private DictDao dictDao;

    public R insert(String k) {
        Dict t = new Dict();
        t.setK(k);
        t.setV("value");
        t.setState(BoolState.NO);
        int i = dictDao.save(t);
        log.info("i:{}",i);
        log.info("t:{}",t);
        return R.OK(i);
    }


    public R page(KMap params) {
        Dict t = new Dict();
        t.setState(BoolState.YES);
        params.startPage();
        List<Dict> select = dictDao.select(t);
        PageInfo<Dict> list = new PageInfo<Dict>(select);
        return R.OK(list);
    }
}
